package org.example.controller;


import org.example.dto.PostPageQueryDTO;
import org.example.result.PageResult;
import org.example.result.Result;
import org.example.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("post")
public class PostController {
    @Autowired
    private PostService postService;

    @RequestMapping("list")
    @Cacheable(value = "postList")
    public Result list(PostPageQueryDTO postPageQueryDTO){
       PageResult pageResult  = postService.listAll(postPageQueryDTO);
        return Result.success(pageResult);
    }

    @RequestMapping("add")
    public Result add(PostPageQueryDTO postPageQueryDTO){
        boolean i = postService.save(postPageQueryDTO);
        return Result.success(i);
    }

    @RequestMapping("update")
    public Result update(PostPageQueryDTO postPageQueryDTO){
        boolean post =postService.update(postPageQueryDTO);
        return Result.success(post);
    }

    @RequestMapping("delById")
    public Result delById(Integer id) {
        boolean i = postService.removeById(id);
        return Result.success(i);

    }

}
